package org.example.struct.array;

import java.util.Arrays;

/**
 * @author liyishan
 * @date 2023/12/7 09:11
 * @apiNote
 */

public class LCP77RuneReserve {

    public static int runeReserve(int[] runes) {
        Arrays.sort(runes);
        int ans = 1, cnt = 1;
        for (int i = 1; i < runes.length; i++) {
            if (runes[i] - runes[i - 1] > 1) {
                cnt = 1;
            } else {
                ans = Math.max(ans, ++cnt);
            }
        }
        return ans;
    }


    public static int test(int[] runes){
        Arrays.sort(runes);
        int n = runes.length;
        int[] dp = new int[n];
        Arrays.fill(dp,1);
        for(int i = 1; i < n; i++){
            for(int j = 0; j < i; j++){
                if(Math.abs(runes[i] - runes[j]) <=1){
                    dp[i] = Math.max(dp[i], dp[j] + 1);
                }
            }
        }
        int max = 0;
        for(int i = 0; i < n; i++){
            max = Math.max(max, dp[i]);
        }
        return max;
    }
}
